/*
 * AnnotatedPoints.java
 * 
 * Created by demory on Dec 11, 2009, 6:59:00 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.rtemaster.gui.map;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author demory
 */
public class AnnotatedPoints implements MapDrawable {

  private Map<Point2D, String> points_;

  private double minX_ = Double.MAX_VALUE, maxX_ = Double.MIN_VALUE, minY_ = Double.MAX_VALUE, maxY_ = Double.MIN_VALUE;

  public AnnotatedPoints() {
    points_ = new HashMap<Point2D, String>();
  }

  public void addPoint(Point2D pt, String annotation) {
    points_.put(pt, annotation);
    minX_ = Math.min(minX_, pt.getX());
    maxX_ = Math.max(maxX_, pt.getX());
    minY_ = Math.min(minY_, pt.getY());
    maxY_ = Math.max(maxY_, pt.getY());
  }

  public void draw(MapCanvas canvas) {
    Graphics2D g2d = canvas.getGraphics();
    g2d.setColor(Color.BLACK);
    g2d.setFont(new Font("Dialog", Font.PLAIN, 10));
    for(Map.Entry<Point2D, String> entry : points_.entrySet()) {
      int x = canvas.getCC().xToScreen(entry.getKey().getX());
      int y = canvas.getCC().yToScreen(entry.getKey().getY());
      g2d.fillOval(x-1, y-1, 3, 3);
      g2d.drawString(entry.getValue(), x+4, y-3);
    }
  }

  public Rectangle2D getBoundingBox() {
    return new Rectangle2D.Double(minX_, minY_, maxX_-minX_, maxY_-minY_);
  }

}
